<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layuimini/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs data-count-edit" lay-event="pass">通过</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="reject">拒绝</a>
        </script>

    </div>
</div>
<script src="../layuimini/js/commons.js"></script>
<script src="../layuimini/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: URL + 'recruiter/interview/selectAllInterview',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'id', width: 80, title: 'ID', sort: true},
                {field: 'name', width: 100, title: '面试名称'},
                {field: 'initiator', width: 150, title: '发起人'},
                {field: 'uid', width: 80, title: '面试者'},
                {field: 'sendTime', title: '发起时间', width: 100},
                {field: 'interviewTime', width: 100, title: '面试时间'},
                {field: 'address', width: 100, title: '面试地址'},
                {field: 'note', width: 100, title: '备注'},
                {field: 'state', width: 80, title: '状态',templet: function(d){

                        //得到当前行数据，并拼接成自定义模板
                        return '<span style="color: #c00;">'+ (d.state == 0 ? "通过" : d.state == 1 ? "待审核" : "拒绝") +'</span>'
                    }},
                {title: '审核', minWidth: 50, templet: '#currentTableBar', fixed: "right", align: "center"}
            ]],
            limits: [10],
            limit: 10,
            page: true,
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.totalCount, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });


        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'pass') {
                console.log(data)
                layer.confirm('确认通过么', function (index) {
                    $.ajax({
                        url: URL + 'admin/pass',
                        data: {"aid":localStorage.getItem("admin"),'cid':data.cid},
                        success: function (result){
                            if (result.code == 0){
                                layer.msg("通过成功",function (){
                                    //执行搜索重载
                                    table.reload('currentTableId', {
                                        page: {
                                            curr: 1
                                        }
                                    }, 'data');
                                })
                            }
                            layer.close(index);
                        }

                    })
                });
                return false;
            } else if (obj.event === 'reject') {
                layer.confirm('确认拒绝么', function (index) {
                    $.ajax({
                        url: URL + 'admin/reject',
                        data: {"aid":localStorage.getItem("admin"),'cid':data.cid},
                        success: function (result){
                            if (result.code == 0){
                                layer.msg("拒绝成功",function (){
                                    //执行搜索重载
                                    table.reload('currentTableId', {
                                        page: {
                                            curr: 1
                                        }
                                    }, 'data');
                                })
                            }
                            layer.close(index);
                        }

                    })
                });
            }
        });

    });
</script>
<script>

</script>

</body>
</html>